<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>圆</title>

    <style>
      #tutorial {
        border: 1px solid red;
      }
    </style>
  </head>
  <body>
    <canvas id="tutorial" width="300" height="300"></canvas>

    <script>
      CanvasRenderingContext2D.prototype.fullCircle = function (style) {
        // 反向获取当前上下文源Canavs元素
        var canvas = this.canvas;
        // 获取最短边半径
        var minRadius = Math.min(canvas.width, canvas.height) / 2;
        // 使用arc() API绘制圆
        this.fillStyle = style || "#000";
        // 绘制
        this.beginPath();
        this.arc(
          canvas.width / 2,
          canvas.height / 2,
          minRadius,
          0,
          2 * Math.PI
        );
        this.fill();
      };
   
      document.getElementById("tutorial").getContext("2d").fullCircle("red")
    </script>
  </body>
</html>
